//
//  BasicInformationViewController.m
//  BigToBig
//
//  Created by admin on 16/4/26.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "BasicInformationViewController.h"
#import "BasicInfoTableViewCell.h"
#import <CommonCrypto/CommonDigest.h>
#import "SKSTableView.h"
#import "SKSTableViewCell.h"
#import "EntrepreneurDetailViewController.h"
#import "ChooseTableViewCell.h"
#import "EditContentTableViewCell.h"
#import "CreatedProjectModel.h"
#import "BaseicInformationModel.h"
#import "QuartzCore/QuartzCore.h"

@interface BasicInformationViewController ()
<
    UITableViewDataSource,
    UITableViewDelegate,
    UITextFieldDelegate,
    UIActionSheetDelegate,
    UIImagePickerControllerDelegate,
    UIScrollViewDelegate,
    SKSTableViewDelegate,
    EditContentTableViewCellDelegate
>

{
    
    UITextField *realName;//真实姓名
    UITextField *compantyName;//公司
    UITextField *JobName;//职位
    UITextField *adressName;//工作地点
    UITextField *wechatNub;//微信号
    UITextField *emailAdress;//邮箱
    UITextField *phoneNub;//电话号
    UITableView *BasicTab;
}

@property (nonatomic, strong)UIButton *headBtn;
@property (nonatomic ,weak)UIScrollView *scro;
@property (nonatomic ,copy)NSString *imgName;
@property (nonatomic ,copy)NSString *email;
@property (nonatomic ,copy)NSString *number;
@property (nonatomic ,weak)UITableView *basicTab;
@property (nonatomic , strong)NSArray *contents;
@property (nonatomic ,strong)SKSTableView *sksTableView;
@property(nonatomic,strong)UIView *addXueli;
@property(nonatomic,strong)UIView *addIdeas;
@property(nonatomic,strong)UITableView *signUpTableView;
@property (nonatomic , strong)NSMutableArray *projectModelArr;
@property(nonatomic,strong)NSMutableArray *sectionTwoArr;
@property (nonatomic , strong)NSMutableDictionary *resultDic;

@end

@implementation BasicInformationViewController

@synthesize btnSelect;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.barTintColor = COLOR_RGBA(77, 155, 255, 1);
    self.view.backgroundColor = [UIColor whiteColor];
    [self createdProject];
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"基本信息";
    [self setBackBar];
    titleLab.textColor = [UIColor whiteColor];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    
    self.sksTableView = [[SKSTableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [self.view addSubview:self.sksTableView];
    self.sksTableView.SKSTableViewDelegate = self;
    self.basicTab = self.sksTableView;
    self.sksTableView.rowHeight = 70;
    

    BasicTab = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)style:UITableViewStylePlain];
    BasicTab.backgroundColor = COLOR_RGBA(242, 242, 242, 1);
    BasicTab.bounces = NO;
    BasicTab.separatorColor = COLOR_RGBA(240, 240, 240, 1);

    self.sksTableView.tableHeaderView = BasicTab;
    BasicTab.delegate = self;
    BasicTab.dataSource = self;
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.resultDic = [NSMutableDictionary new];
    [self addEducationExp];
    [self createAddXueli];
    [self createIdeas];

    
}
#pragma mark Loading数据
- (void)createdProject{
    self.projectModelArr = [NSMutableArray new];
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];
    NSLog(@"%@",UID);
    NSDictionary *params = @{@"user_id":UID};
    NSString *urlStr = [NSString stringWithFormat:@"http://61.135.176.43:6080/bigtobig/project/show_projects?user_id=%@",UID];
    [HttpTool textHTMLPostWithURL:urlStr params:params success:^(id json) {

        NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSArray *projectsArr = [dict objectForKey:@"projects"];
        for (NSDictionary *dic in projectsArr) {
            CreatedProjectModel *model = [CreatedProjectModel CreatedProjectModelWithDict:dic];
            [self.projectModelArr addObject:model];
        }
        NSLog(@"%d %@",__LINE__,projectsArr);
        [self.basicTab reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        
    }];
}
#pragma mark 添加学历View
- (void)createAddXueli{
    self.addXueli = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.addXueli.backgroundColor = COLOR_RGBA(25, 26, 27, 0.8);
    
    UIView *xueliView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight/2 - 150, kScreenWidth, 300)];
    xueliView.backgroundColor = [UIColor whiteColor];
    [self.addXueli addSubview:xueliView];
    
    UILabel *xueliLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 100, 30)];
    xueliLab.text = @"最高学历";
    [xueliView addSubview:xueliLab];
    
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, xueliLab.maxY + 5, kScreenWidth, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [xueliView addSubview:line];
    
    UILabel *descrabLab = [[UILabel alloc] initWithFrame:CGRectMake(10, line.maxY + 5, kScreenWidth - 20, 25)];
    descrabLab.font = [UIFont systemFontOfSize:14];
    descrabLab.text = @"根据您的教育经历结识正在创业或投资的校友";
    descrabLab.textColor = [UIColor grayColor];
    [xueliView addSubview:descrabLab];
    
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(15, descrabLab.maxY + 5, 70, 25)];
    lab.font = [UIFont systemFontOfSize:14];
    lab.text = @"最高学历:";
    [xueliView addSubview:lab];
    
    btnSelect = [[UIButton alloc] initWithFrame:CGRectMake(lab.maxX + 10, descrabLab.maxY + 5, kScreenWidth - 120, 25)];
    btnSelect.backgroundColor = [UIColor whiteColor];
    [xueliView addSubview:btnSelect];
    
    btnSelect.layer.borderWidth = 1;
    btnSelect.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    btnSelect.layer.cornerRadius = 5;
    
    [btnSelect addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    UITextField *school = [[UITextField alloc] initWithFrame:CGRectMake(20, btnSelect.maxY + 15, kScreenWidth - 40, 25)];
    school.placeholder = @"学校名称";
    school.layer.borderWidth = 1;
    school.layer.borderColor = [COLOR_RGBA(135, 135, 135, 1) CGColor];
    school.textAlignment = NSTextAlignmentCenter;
    school.delegate = self;
    [xueliView addSubview:school];
    
    UITextField *college = [[UITextField alloc] initWithFrame:CGRectMake(20, school.maxY + 15, kScreenWidth - 40, 25)];
    college.placeholder = @"学院";
    college.layer.borderWidth = 1;
    college.layer.borderColor = [COLOR_RGBA(135, 135, 135, 1) CGColor];
    college.textAlignment = NSTextAlignmentCenter;
    college.delegate = self;
    [xueliView addSubview:college];
    
    UILabel *year = [[UILabel alloc] initWithFrame:CGRectMake(15, college.maxY + 15, 70, 25)];
    year.font = [UIFont systemFontOfSize:14];
    year.text = @"毕业年份:";
    [xueliView addSubview:year];
    
    yearSelect = [[UIButton alloc] initWithFrame:CGRectMake(lab.maxX + 10, college.maxY + 15, kScreenWidth - 120, 25)];
    yearSelect.backgroundColor = [UIColor whiteColor];
    [xueliView addSubview:yearSelect];    
    
    yearSelect.layer.borderWidth = 1;
    yearSelect.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    yearSelect.layer.cornerRadius = 5;
    
    [yearSelect addTarget:self action:@selector(clickYear:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *linet = [[UILabel alloc] initWithFrame:CGRectMake(0, 252, kScreenWidth, 1)];
    linet.backgroundColor = [UIColor lightGrayColor];
    [xueliView addSubview:linet];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    backBtn.frame = CGRectMake(kScreenWidth/2, 263, (kScreenWidth/2 - 10)/ 2, 25);
    backBtn.backgroundColor = [UIColor lightGrayColor];
    backBtn.layer.cornerRadius = 5;
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn setTitle:@"取消" forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(hidView:) forControlEvents:UIControlEventTouchUpInside];
    [xueliView addSubview:backBtn];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    sureBtn.frame = CGRectMake(backBtn.maxX + 5, 263, (kScreenWidth/2 - 10)/ 2, 25);
    [sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    sureBtn.layer.cornerRadius = 5;
    sureBtn.backgroundColor = [UIColor redColor];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [xueliView addSubview:sureBtn];
    
}

#pragma mark 添加创业理念View
- (void)createIdeas{
    self.addIdeas = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.addIdeas.backgroundColor = COLOR_RGBA(25, 26, 27, 0.8);
    
    UIView *ideasView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight/2 - 150, kScreenWidth, 300)];
    ideasView.backgroundColor = [UIColor whiteColor];
    [self.addIdeas addSubview:ideasView];
    
    UILabel *xueliLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 100, 30)];
    xueliLab.text = @"创业理念";
    [ideasView addSubview:xueliLab];
    
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, xueliLab.maxY + 5, kScreenWidth, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [ideasView addSubview:line];
    
    UILabel *descrabLab = [[UILabel alloc] initWithFrame:CGRectMake(10, line.maxY + 5, kScreenWidth - 20, 35)];
    descrabLab.font = [UIFont systemFontOfSize:14];
    descrabLab.text = @"您和其他创业者在创业道路上最大的不同是什么?";
    descrabLab.numberOfLines = 0;
    descrabLab.textColor = [UIColor grayColor];
    [ideasView addSubview:descrabLab];
    
    UILabel *border = [[UILabel alloc] initWithFrame:CGRectMake(15, descrabLab.maxY + 5, kScreenWidth - 30, 130)];
    border.layer.borderWidth = 1;
    [ideasView addSubview:border];
    
    UILabel *ideaLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, kScreenWidth - 50, 120)];
    ideaLab.font = [UIFont systemFontOfSize:14];
    ideaLab.numberOfLines = 0;
    ideaLab.text = @"创业理念川药业理念创业理念川药业理念创业理念川药业理念创业理念川药业理念创业理念川药业理念创业理念川药业理念创业理念川药业理念创业理念川药业理念创业理念川药业理念";
    [border addSubview:ideaLab];
    
    
    UILabel *linet = [[UILabel alloc] initWithFrame:CGRectMake(0, 252, kScreenWidth, 1)];
    linet.backgroundColor = [UIColor lightGrayColor];
    [ideasView addSubview:linet];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    backBtn.frame = CGRectMake(kScreenWidth/2, 263, (kScreenWidth/2 - 10)/ 2, 25);
    backBtn.backgroundColor = [UIColor lightGrayColor];
    backBtn.layer.cornerRadius = 5;
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn setTitle:@"取消" forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(hidView:) forControlEvents:UIControlEventTouchUpInside];
    [ideasView addSubview:backBtn];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    sureBtn.frame = CGRectMake(backBtn.maxX + 5, 263, (kScreenWidth/2 - 10)/ 2, 25);
    [sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    sureBtn.layer.cornerRadius = 5;
    sureBtn.backgroundColor = [UIColor redColor];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [ideasView addSubview:sureBtn];
    
}

- (void)clickYear:(UIButton *)btn{
    NSArray * arr = [[NSArray alloc] init];
    arr = [NSArray arrayWithObjects:@"2016",@"2015",@"2014",@"2013",@"2012",@"2011",@"2010",@"2009",@"2008", nil];
    if(dropDown == nil) {
        CGFloat f = arr.count * 40;
        dropDown = [[NIDropDown alloc]showDropDown:btn :&f :arr :@"down"];
        dropDown.delegate = self;
    }
    else {
        [dropDown hideDropDown:btn];
        [self rel];
    }
}

- (void)click:(UIButton *)btn{
    NSArray * arr = [[NSArray alloc] init];
    arr = [NSArray arrayWithObjects:@"本科", @"硕士", @"博士",nil];
    if(dropDown == nil) {
        CGFloat f = arr.count * 40;
        dropDown = [[NIDropDown alloc]showDropDown:btn :&f :arr :@"down"];
        dropDown.delegate = self;
    }
    else {
        [dropDown hideDropDown:btn];
        [self rel];
    }
}

- (void)viewDidUnload {
    btnSelect = nil;
    [self setBtnSelect:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void) niDropDownDelegateMethod: (NIDropDown *) sender {
    [self rel];
}

-(void)rel{
    dropDown = nil;
}

#pragma mark 取消(最高学历)
- (void)hidView:(UIButton *)btn{
    
    [self.addXueli removeFromSuperview];
    [self.addIdeas removeFromSuperview];
}

#pragma mark 添加教育经历
- (void)addEducationExp{
    
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];
    
    NSDictionary *params = @{@"user_id":UID};
    
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/educational_experience/show_all?" params:params success:^(id json) {
        
        self.sectionTwoArr = [NSMutableArray array];
        for (NSDictionary *dic in json[@"educational_experience"]) {
            BaseicInformationModel *bsaeModel = [[BaseicInformationModel alloc] init];
            [bsaeModel setValuesForKeysWithDictionary:dic];
            [self.sectionTwoArr addObject:bsaeModel];
        }
        [BasicTab reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
}

- (NSArray *)contents
{
    if (!_contents) {
        _contents = @[@[@[@"创建的项目", @"创业生态园",@"创业生态园"]],
                      @[@[@"我的创业导师", @"创业生态园", @"创业生态园"]],
                      @[@[@"我的创业伙伴", @"创业生态园", @"创业生态园",@"创业生态园"]]
                      ];
    }
    
    return _contents;
}


- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
    BackButton *saveBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(kScreenWidth - 44,0 , 44, 44);
    [saveBtn addTarget:self action:@selector(SaveMessage) forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 6;
    if (tableView == self.sksTableView) {
        return self.contents.count;
    }
    else{
        return 3;
    }
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.sksTableView) {
        return [self.contents[section] count];
    }
    else{
    
        if (section == 0) {
        
            return 5;
            
        }if (section == 1) {
            
            return 3;
        }if (section == 2){
            return 2;
//        }if (section == 3){
//            return 2;
//        }if (section == 4) {
//            return 2;
//        }if (section == 5) {
//            return 3;
        }else{
        
            self.basicTab.separatorStyle = UITableViewCellSeparatorStyleNone;
            return 0;
        }
    }
}

- (NSInteger)tableView:(SKSTableView *)tableView numberOfSubRowsAtIndexPath:(NSIndexPath *)indexPath
{
    return self.projectModelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.sksTableView) {
        static NSString *CellIdentifier = @"SKSTableViewCell";
        
        SKSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        if (!cell)
            cell = [[SKSTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
        cell.textLabel.text = self.contents[indexPath.section][indexPath.row][0];
        if (indexPath.section == 0) {
            if (self.projectModelArr.count == 0) {
                cell.isExpandable = NO;
            }
            else{
                cell.isExpandable = YES;
            }
        }
        return cell;

    }
    else{
    
    NSString *cellID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    
    if (indexPath.section == 0) {
        
        EditContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[EditContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.editContentCellDelegate = self;
        }
        
        
        if (indexPath.row == 0) {
            
            UILabel *headLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 10, 60, 60)];
            headLabel.font = [UIFont systemFontOfSize:14];
            headLabel.text = @"头像";
            headLabel.textAlignment = NSTextAlignmentLeft;
            [cell.contentView addSubview:headLabel];
            
            UIButton *headBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth - 25 - 60,10,60,60)];
            self.headBtn = headBtn;
            [self iconInit];
            [self.headBtn addTarget:self action:@selector(changeIcon) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:headBtn];
            cell.accessoryType = UITableViewCellAccessoryNone;
            
        }if (indexPath.row == 1) {
            
            NSUserDefaults* name = [NSUserDefaults standardUserDefaults];
            NSString *NAME = [name objectForKey:@"name"];
            NSLog(@"%@",NAME);
            cell.leftLab.text = @"真实姓名";
            cell.contetField.placeholder = @"请输入真实姓名";
            cell.keyStr = @"name";
            if (NAME != nil) {
                cell.contetField.text = NAME;
                [self.resultDic setObject:NAME forKey:cell.keyStr];
            }
            
            
        }if (indexPath.row == 2) {

            NSUserDefaults* companyDefaults = [NSUserDefaults standardUserDefaults];
            NSLog(@"%@",companyDefaults);
            NSString *company = [companyDefaults objectForKey:@"company"];
            cell.leftLab.text = @"公司";
            cell.contetField.placeholder = @"请输入公司名字";
            cell.keyStr = @"company_name";
            if (company != nil) {
                cell.contetField.text = company;
                [self.resultDic setObject:company forKey:cell.keyStr];

            }
            
        }if (indexPath.row == 3) {
            
            
            NSUserDefaults* jobDefaults = [NSUserDefaults standardUserDefaults];
           NSString *job = [jobDefaults objectForKey:@"jobName"];
            cell.leftLab.text = @"职位";
            cell.contetField.placeholder = @"请输入职位";
            cell.keyStr = @"job_title";
            if (job != nil) {
                cell.contetField.text = job;
                [self.resultDic setObject:job forKey:cell.keyStr];

            }
        }if (indexPath.row == 4) {
            
            
            NSUserDefaults* adressDefaults = [NSUserDefaults standardUserDefaults];
           NSString *address = [adressDefaults objectForKey:@"adress"];
            cell.leftLab.text = @"工作地点";
            cell.keyStr = @"city";
            cell.contetField.placeholder = @"请输入工作地点";
            if (address != nil) {
                cell.contetField.text = address;
                [self.resultDic setObject:address forKey:cell.keyStr];
            }
        }
        return cell;
        
    }if (indexPath.section == 1) {
        
        EditContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[EditContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.editContentCellDelegate = self;
        }

        if (indexPath.row == 0) {
            
            NSUserDefaults* weChatDefaults = [NSUserDefaults standardUserDefaults];
            NSString *wechat = [weChatDefaults objectForKey:@"weChat"];
            
            cell.leftLab.text = @"微信号";
            
            if (wechat == nil) {
                
                cell.contetField.text = @"未验证";
                
            }else{
                
                cell.contetField.text = wechat;
                
                
            }
            cell.contetField.placeholder = @"请输入微信号";

        }if (indexPath.row == 1) {
            
            cell.leftLab.text = @"邮箱";
            cell.contetField.enabled = NO;
            NSUserDefaults* emailDefaults = [NSUserDefaults standardUserDefaults];
            self.email = [emailDefaults objectForKey:@"email"];
            NSString *emailStr = [NSString stringWithFormat:@"%@",self.email];
            
            if (self.email == nil) {
                
                cell.contetField.text = @"未验证";
                
            }else{
                
                cell.contetField.text = emailStr;
                
                
            }
            
        }if (indexPath.row == 2) {
            
            NSUserDefaults* phoneNumberDefaults = [NSUserDefaults standardUserDefaults];
            self.number = [phoneNumberDefaults objectForKey:@"phoneNumber"];
            NSString *phoneNumber1 = [NSString stringWithFormat:@"%@",self.number];
            cell.contetField.enabled = NO;
            cell.leftLab.text = @"电话号";
            if (self.number == nil) {
                cell.contetField.text = @"未验证";
            }else{
                cell.contetField.text = phoneNumber1;
            }
            
        }

        return cell;
        
    }
        if (indexPath.section == 2) {
        
        ChooseTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            
        cell=[[ChooseTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.leftLab.font = [UIFont systemFontOfSize:13];
        cell.rightLab.font = [UIFont systemFontOfSize:13];


        if (indexPath.row == 0) {
            cell.leftLab.text = @"最高学历";
     
            if (self.sectionTwoArr.count == 0) {
                cell.rightLab.text = @"还没有添加学历";
            }else{
                BaseicInformationModel *bsaeModel = self.sectionTwoArr[indexPath.row];
                NSString *eduStr = [NSString stringWithFormat:@"%@%@%@%@%@",bsaeModel.college_name,@" ",bsaeModel.academy,@" ",bsaeModel.graduation_date];
                cell.rightLab.text = eduStr;
                cell.rightLab.textColor = [UIColor blackColor];
                
            }
            
            
        }if (indexPath.row == 1) {
            cell.leftLab.text = @"创业理念";
            cell.rightLab.text = @"还没有写创业理念";
        }
        
        return cell;
    }

    else{
        return 0;
    }
    
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForSubRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"BasicInfoTableViewCell";
    
    BasicInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    CreatedProjectModel *model = self.projectModelArr[indexPath.row];
    if (!cell)
        cell = [[BasicInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    [cell.headPic sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.bigtobig.com/%@",model.project_logo]] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    cell.nameLabel.text = model.project_name;
    cell.describe.text = model.brief_introduction;
    tableView.rowHeight = 80;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        return 0;
    }
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            return 80;
        }
        else{
        
            return 50;
        }
        
    }if (indexPath.section == 1) {
        return 50;
        
    }if (indexPath.section == 3 || indexPath.section == 4 || indexPath.section == 5) {
        if (indexPath.row == 0) {
            
            return 50;
        }
        else{
            
            return 100;
        }

    }else{
    
        return 80;
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    UILabel *lb = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    
    lb.font = [UIFont systemFontOfSize:12.0];
    
    if (section == 1) {
        
        return nil;
        
    }else{
        
        return nil;
    }
}
- (void)saveMessageWithValue:(NSString *)value andKey:(NSString *)key{
    if ([key isEqualToString:@"真实姓名"]) {
        key = @"name";
    }else if([key isEqualToString:@"公司"]){
        key = @"company_name";
    }
    else if ([key isEqualToString:@"职位"]){
        key = @"job_title";
    }else if ([key isEqualToString:@"工作地点"]){
        key = @"city";
    }else if ([key isEqualToString:@"微信号"]){
        key = @"wechat";
    }else if ([key isEqualToString:@"邮箱"]){
        key = @"email";
    }else if ([key isEqualToString:@"电话号"]){
        key = @"phoneNumber";
    }
    
    [self.resultDic setObject:value forKey:key];

    
}


#pragma mark tableView点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(tableView == self.sksTableView){
        if (indexPath.section == 0 && indexPath.row != 0) {
            EntrepreneurDetailViewController *entrepreneurDetailVC  = [[EntrepreneurDetailViewController  alloc]init];
            [self.navigationController pushViewController:entrepreneurDetailVC animated:YES];
            CreatedProjectModel *model = self.projectModelArr[indexPath.row - 1];
            entrepreneurDetailVC.model = model;
        }
        else{
            NSLog(@"%ld , %ld",indexPath.section , indexPath.row);
        }
    }
    else{
        if (indexPath.section == 2) {
            if (indexPath.row == 0) {
                
                [self.navigationController.view addSubview:_addXueli];
                
            }if (indexPath.row == 1) {
                [self.navigationController.view addSubview:_addIdeas];
            }
        }
    }
    

}


#pragma mark 保存信息
- (void)SaveMessage{
    
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *uid = [userID objectForKey:@"userID"];
    [self.resultDic setObject:uid forKey:@"id"];
//    NSLog(@"%@",self.resultDic);
//    NSDictionary *params = @{@"id":uid,@"company_name":compantyName.text,@"job_title":JobName.text,@"wechat":wechatNub.text,@"city":adressName.text};
    
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/user/update_by_id?" params:self.resultDic success:^(id json) {
        
        NSString *returnCode = [NSString stringWithFormat:@"%@",json[@"return_code"]];
        if([returnCode isEqualToString:@"0"]){
            
            [UIView animateWithDuration:2.0 animations:^{
                
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"保存成功";
                [hud hide:YES afterDelay:2];
                
                NSUserDefaults* jobDefaults = [NSUserDefaults standardUserDefaults];
                [jobDefaults setObject:[self.resultDic objectForKey:@"job_title"]forKey:@"jobName"];
                [jobDefaults synchronize];
                
                NSUserDefaults* weChatDefaults = [NSUserDefaults standardUserDefaults];
                [weChatDefaults setObject:[self.resultDic objectForKey:@"wechat"] forKey:@"weChat"];
                [weChatDefaults synchronize];
                
                NSUserDefaults* companyDefaults = [NSUserDefaults standardUserDefaults];
                [companyDefaults setObject:[self.resultDic objectForKey:@"company_name"] forKey:@"company"];
                [companyDefaults synchronize];
                
                NSUserDefaults* adressDefaults = [NSUserDefaults standardUserDefaults];
                [adressDefaults setObject:[self.resultDic objectForKey:@"city"] forKey:@"adress"];
                [adressDefaults synchronize];
                
//                NSUserDefaults *wechatDefaults = [NSUserDefaults standardUserDefaults];
//                [weChatDefaults setObject:wechatNub.text forKey:@"weChat"];
//                [weChatDefaults synchronize];

                
                
            } completion:^(BOOL finished) {
                
                [NSThread sleepForTimeInterval:1.0];
                
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setObject:self.savedImage forKey:@"saveImage"];
                NSNotificationCenter * notificationCenter = [ NSNotificationCenter defaultCenter];
                [notificationCenter postNotificationName:@"AnyNotification" object:nil userInfo:dict];
                [self.navigationController popViewControllerAnimated:YES];
                
            }];
            
        }
        
    } failure:^(NSError *error) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [UIView animateWithDuration:2.0 animations:^{
                
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"保存失败";
                [hud hide:YES afterDelay:2];
                
            } completion:^(BOOL finished) {
                
                [NSThread sleepForTimeInterval:1.0];
                
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setObject:self.savedImage forKey:@"saveImage"];
                NSNotificationCenter * notificationCenter = [ NSNotificationCenter defaultCenter];
                [notificationCenter postNotificationName:@"AnyNotification" object:nil userInfo:dict];
                [self.navigationController popViewControllerAnimated:YES];
                
            }];
            
        });
        
    }];
    
}
#pragma mark 返回事件
- (void)backController:(UIButton *)btn{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden = NO;
}
//- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//    
//    
//    //回退键盘
//    return [textField endEditing:YES];
//}

//以下都是设置头像
- (void)iconInit{
    
    if (!self.savedImage)
    {
        //默认头像
        [self.headBtn setImage:[UIImage imageNamed:@"tx"] forState:UIControlStateNormal];
    }
    else
    {
        [self.headBtn setImage:self.savedImage forState:UIControlStateNormal];
    }
    self.headBtn.layer.masksToBounds = YES;
    
    self.headBtn.layer.cornerRadius = self.headBtn.frame.size.height / 2;
    
}

- (void)changeIcon
{
    
    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    
    if (status == NotReachable) {
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请联网后设置头像";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
        return;
        
    }

    UIAlertController *alertController;
    
    __block NSUInteger blockSourceType = 0;
    
    // 判断是否支持相机因为模拟器不支持相机所以在模拟器上不会有相机这个选项
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        //支持访问相机与相册情况
        alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击从相册中选取");
            //相册
            //            blockSourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            
            imagePickerController.delegate = self;
            
            imagePickerController.allowsEditing = YES;
            
            imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            [self presentViewController:imagePickerController animated:YES completion:nil];
        }]];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击拍照");
            //相机
            //            blockSourceType = UIImagePickerControllerSourceTypeCamera;
            
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            
            imagePickerController.delegate = self;
            
            imagePickerController.allowsEditing = YES;
            
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            
            [self presentViewController:imagePickerController animated:YES completion:nil];
        }]];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击取消");
            // 取消
            return;
        }]];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }
    else
    {
        //只支持访问相册情况
        alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
//            NSLog(@"点击从相册中选取");
            //相册
            blockSourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            
            imagePickerController.delegate = self;
            
            imagePickerController.allowsEditing = YES;
            
            imagePickerController.sourceType = blockSourceType;
            
            [self presentViewController:imagePickerController animated:YES completion:^{
                
            }];
        }]];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
//            NSLog(@"点击取消");
            // 取消
            return;
        }]];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }
}

#pragma mark - 选择图片后,回调选择

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    /* 此处info 有六个可选类型
     * UIImagePickerControllerMediaType; // an NSString UTTypeImage)
     * UIImagePickerControllerOriginalImage;  // a UIImage 原始图片
     * UIImagePickerControllerEditedImage;    // a UIImage 裁剪后图片
     * UIImagePickerControllerCropRect;       // an NSValue (CGRect)
     * UIImagePickerControllerMediaURL;       // an NSURL
     * UIImagePickerControllerReferenceURL    // an NSURL that references an asset in the AssetsLibrary framework
     * UIImagePickerControllerMediaMetadata    // an NSDictionary containing metadata from a captured photo
     */
    
//    NSLog(@"%@",image);
    self.savedImage = image;
    [self.headBtn setImage:image forState:UIControlStateNormal];
    
//        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//        //把uidStr即用户的id作为key进行图片名称的存储这样能保证不同的用户取到的不同的图片
////        NSLog(@"%@",uidStr);
//        [userDefaults setObject:self.imgName forKey:uidStr];
//        [userDefaults synchronize];
    NSUserDefaults *UserID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [UserID objectForKey:@"userID"];
    
    NSString *uidStr = [NSString stringWithFormat:@"%@",UID];
    
    NSString *str1 = [self md5HexDigest:uidStr];
    
    NSString *b = [str1 substringWithRange:NSMakeRange(8,16)];
    NSString *str2 = @".png";
    NSString *imgName = [NSString stringWithFormat:@"%@%@",b,str2];

    [self saveImage:image withName:imgName];
}

#pragma mark - 保存图片至本地沙盒
//#define boundary @"itcast-upload"

- (NSString *)md5HexDigest:(NSString*)password
{
    const char *original_str = [password UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(original_str, strlen(original_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++)
    {
        [hash appendFormat:@"%02X", result[i]];
    }
    NSString *mdfiveString = [hash lowercaseString];
    
    NSLog(@"Encryption Result = %@",mdfiveString);
    return mdfiveString;
}
- (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
    
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *Uid = [userID objectForKey:@"userID"];
    NSString *uidStr = [NSString stringWithFormat:@"%@",Uid];
    NSString *str1 = [self md5HexDigest:uidStr];
    NSString *b = [str1 substringWithRange:NSMakeRange(8,16)];
    NSString *str2 = @".png";
    NSString *imgName = [NSString stringWithFormat:@"%@%@",b,str2];
    self.imgName = imgName;
    
    NSLog(@"%@",imgName);
    
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.8);
    
    [[AFHTTPSessionManager manager] POST:@"61.135.176.43:6080/picture/picture/head_portrait.json" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
        [formData appendPartWithFileData:imageData name:@"userfile" fileName:imgName mimeType:@"image/png"];
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
    }];
    
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imgName];
    
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [realName resignFirstResponder];
    [compantyName resignFirstResponder];
    [adressName resignFirstResponder];
    [JobName resignFirstResponder];
    [wechatNub resignFirstResponder];
    [emailAdress resignFirstResponder];
    [phoneNub resignFirstResponder];
}


//结束编辑回退到原点
- (void)textFieldDidEndEditing:(UITextField *)textField{
    
    [UIView animateWithDuration:0.5 animations:^{
        
        self.scro.frame =CGRectMake(0, 0, self.scro.frame.size.width, self.scro.frame.size.height);
        
    }];
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    textField.keyboardAppearance = UIReturnKeyDone;

    return [textField endEditing:YES];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    if (textField == realName) {
  
        [UIView animateWithDuration:0.5 animations:^{
            
            self.scro.contentOffset = CGPointMake(0, 216-kScreenHeight+compantyName.maxY+164);
            
        }];
        
    }if (textField == compantyName) {

        [UIView animateWithDuration:0.5 animations:^{
            
            self.scro.contentOffset = CGPointMake(0, 216-kScreenHeight+compantyName.maxY+164+50);
            
        }];
    }if (textField == JobName) {

        [UIView animateWithDuration:0.5 animations:^{
            
            self.scro.contentOffset = CGPointMake(0, 216-kScreenHeight+compantyName.maxY+164+50+50);
        }];
        
    }if (textField == adressName) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.scro.contentOffset = CGPointMake(0,216-kScreenHeight+compantyName.maxY+164+50+50+80);
        }];
        
    }if (textField == wechatNub) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.scro.contentOffset = CGPointMake(0, 216-kScreenHeight+compantyName.maxY+164+ 50+50+80+50);
            
        }];
        
    }if (textField == emailAdress) {

        [UIView animateWithDuration:0.5 animations:^{

            self.scro.contentOffset = CGPointMake(0, 216-kScreenHeight+compantyName.maxY+164+ 50+50+80+50+50);
            
        }];
        
    }if (textField == phoneNub) {

        [UIView animateWithDuration:0.5 animations:^{
            
            self.scro.contentOffset = CGPointMake(0, 216-kScreenHeight+compantyName.maxY+164+ 50+50+80+50+50);
            
        }];
        
    }
}

@end

